#ifndef H_TYPES_20071013
#define H_TYPES_20071013

#include "header.h"
#include "macros.h"

typedef unsigned short ushort;
typedef unsigned long ulong;
typedef unsigned char uchar;


typedef struct Data{
	void* data;
	struct Data *pred,
				*next;
}Data;


typedef struct List{
	Data *head,
		 *tail;
	Data *iter;
	int counter;
}List;

typedef struct HashTable{

	/* private */
	void *iter;
	List *CurrList;
	
	/* Public */
	List **indexes,
		  *Table;
	int size;
	int counter;

	int (*compare)(void* E1, void* E2);
	int (*getHash)(struct HashTable *this, void* E);
	
	/* methods */	
/*	void  delete			(struct HashTable* this, void *element);own?*/
	

}HashTable;

typedef struct{
	char* map;
	size_t size;
}File;

typedef struct{
	int Socket,
		isBusy;
	pthread_mutex_t	mutex;
}SecSockets;

typedef struct{

	char cmd[CMDSIZE+1],
	     tail[TAILSIZE+1];
}Message;

typedef struct{/*table users*/

	char user[USERSIZE+1];
	int level;

}ChannelClient;

typedef struct{

	char name[TABLENAMESIZE+1];
	int level;

}ClientChannel;

typedef struct{/*table blacklist*/

	char nick[NICKSIZE+1],
	     user[USERSIZE+1],
		 host[HOSTSIZE+1];

}BlackList;


typedef struct{

	ulong id;
	SecSockets Socket;
	char nick[NICKSIZE+1],
	     user[USERSIZE+1],
	     host[HOSTSIZE+1],
	     status,
		 power,
		 playing;
	ulong cash;
    int level;

	int owntb; /*#### set to 1 if the user already owns a channel. Note: To remove!*/

	List *channels;

}Client;

typedef struct{
	char cmd[CMDSIZE+1];
	int level;
	void (*go)(Client *me, char tail[TAILSIZE+1]); /* pointer to the function wich performs the requested command */
}Command;

typedef struct Module{

	char name[MODULENAMESIZE+1],
	     author[MODULEAUTHORSIZE+1],
		 fullpath[64+1];
	void* id;
	char desc[MODULEDESCSIZE+1];
	char version[MODULEVERSIONSIZE+1];
}Module;

typedef struct{

	unsigned int Port, SslPort;
	int MaxQueuLen,
		MaxClones;
}NetworkConfig;

typedef struct{

	char Host[128],
		 User[64],
		 Pwd[32],
		 DB[16];
	unsigned int Port;
}MysqlConfig;

typedef struct{

	int MaxThreads,
		PollThreads,
		AuthThreads,
		MaxClients,
		MaxChannels,
		MaxGamesPerUser,
		EnableMemDebug,
		EnableSysDebug;
}ServerConfig;

typedef struct{

	pthread_mutex_t mutex;
	FILE *fd;
}DebugFile;

typedef struct ID{
	Client *client;
}ID;

typedef struct Thread{

	pthread_t thid;
	List *ids_list;
	int MaxFds;
	int MaxClients;
	pthread_mutex_t ids_mutex;
}Thread;

typedef struct Peer{

	struct sockaddr_in sin;
	int Socket;
}Peer;

typedef struct{

	ushort id;
	char name[CHAN_MAXNAMESIZE+1];
	char topic[CHAN_MAXTOPICSIZE+1];
	uchar modes;
	int owner;
	List* clients;
	List* blacklist;
}Channel;

#endif
